package com.SHA1604.tiger.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.SHA1604.tiger.R;

import java.util.HashMap;
import java.util.List;

/**
 * ***********************************************************
 * author: jie
 * time: 2016/7/27 22:43
 * name:
 * overview:Build.VERSION.SDK_INT:版本号
 * usage:
 * *************************************************************
 */
public class MeAdapter extends BaseAdapter{
    private final int TYPE_TITLE = 0;
    private final int TYPE_BANNER = 2;
    private final int TYPE_COUNT = TYPE_BANNER+1;
    private List<HashMap<String,Object>> mDatas;
    private Context mContext;

    public MeAdapter(Context context,List<HashMap<String,Object>> datas){
        this.mContext = context;
        this.mDatas = datas;
    }
    @Override
    public int getItemViewType(int position) {
        if (position==2){
            return TYPE_BANNER;
        }else {
            return TYPE_TITLE;
        }
    }

    class My_ItemOne{
        private ImageView mImageView;
        private TextView mTextView;
        public My_ItemOne(View view){
            mImageView = (ImageView) view.findViewById(R.id.me_item_iv1);
            mTextView = (TextView) view.findViewById(R.id.me_item_tv1);
        }
    }
    class My_ItemBanner {
        private ImageView mImageView_iv;
        private TextView mTextView_tv;
        public My_ItemBanner(View view) {
            mImageView_iv = (ImageView) view.findViewById(R.id.me_item_banner_iv1);
            mTextView_tv = (TextView) view.findViewById(R.id.me_item_banner_tv1);
        }
    }
    @Override
    public int getViewTypeCount() {
        return TYPE_COUNT;
    }

    @Override
    public int getCount() {
        return mDatas == null?0:mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        int itemtype = getItemViewType(position);
        My_ItemOne my_itemone = null;
        My_ItemBanner my_itembanner = null;
        if (convertView==null){
            switch (itemtype){
                case TYPE_TITLE:
                    convertView = LayoutInflater.from(mContext).inflate(R.layout.item_me_aa,parent,false);
                    my_itemone = new My_ItemOne(convertView);
                    convertView.setTag(my_itemone);
                    break;
                case TYPE_BANNER:
                    convertView = LayoutInflater.from(mContext).inflate(R.layout.item_me_aa_banner,parent,false);
                    my_itembanner = new My_ItemBanner(convertView);
                    convertView.setTag(my_itembanner);
                    break;
            }
        }else {
            switch (itemtype){
                case TYPE_TITLE:
                    my_itemone = (My_ItemOne) convertView.getTag();
                    break;
                case TYPE_BANNER:
                    my_itembanner = (My_ItemBanner) convertView.getTag();
                    break;
            }
        }

        switch (itemtype){
            case TYPE_TITLE:
                HashMap<String, Object> map = mDatas.get(position);
                int id = (int) map.get("id");
                String title= (String) map.get("title");
                my_itemone.mImageView.setImageResource(id);
                my_itemone.mTextView.setText(title);
                break;
            case TYPE_BANNER:
                HashMap<String, Object> hashMap = mDatas.get(position);
                int mapid = (int) hashMap.get("id");
                String maptitle = (String) hashMap.get("title");
                my_itembanner.mImageView_iv.setImageResource(mapid);
                my_itembanner.mTextView_tv.setText(maptitle);
                break;
        }
        return convertView;
    }


}
